package com.devicemantra.coordinate.interfaces.sms;

import java.io.IOException;
import java.util.Date;
import com.devicemantra.coordinate.util.*;
import com.devicemantra.coordinate.util.CLogger;

import javax.servlet.http.*;




import com.google.appengine.api.labs.taskqueue.Queue;
import com.google.appengine.api.labs.taskqueue.QueueFactory;
import com.google.appengine.api.labs.taskqueue.TaskHandle;
import com.google.appengine.api.labs.taskqueue.TaskOptions.Method;

import static com.google.appengine.api.labs.taskqueue.TaskOptions.Builder.*;


@SuppressWarnings("serial")
public class SMSTask extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		CLogger.log("SMS task started");
		String lMobileNumber = req.getParameter("mobile_number");
		String lMessage = req.getParameter("message");
		String lLangCode = req.getParameter("lang");
		SMS lSMS = SMSFactory.creatNewSMS();
		
		if(lLangCode.equals("ar"))
		{
		      lSMS.setLanguage(1);	
		}
		else
		{
			  lSMS.setLanguage(0); 	
		}
		
		lSMS.setMobileNumber(lMobileNumber);
		lSMS.setMessage(lMessage);
		SMSFactory.sendSMS(lSMS);
		CLogger.log("Sent SMS to " + lMobileNumber + " Message " + lMessage);
		System.out.println("Sent SMS to " + lMobileNumber + " Message " + lMessage);
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
	throws IOException 
	{
		doGet(req,resp);
	}
}
